package com.controller;


import com.github.pagehelper.PageInfo;
import com.pojo.Sitepoint;
import com.service.SiteService;
import com.vo.Result;
import com.vo.SitePointTwoVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/Site")
public class SitePointTwoController {
    @Resource
    private SiteService siteService;

    private Integer routeid;

//巡查点
    @RequestMapping("/SitePointTwo/index")
    public String toSitepoint(Integer id){
        routeid = id;
        return "/Site/SitePointTwo";
    }


    @RequestMapping("/SitePointTwo/show")
    @ResponseBody
    public Result select(@RequestBody SitePointTwoVo sitePointTwoVo){
        sitePointTwoVo.setRouteid(routeid);
        sitePointTwoVo.setShifou(1);
        PageInfo<Sitepoint> sitepointPageInfo = siteService.selectAllSitepoint2(sitePointTwoVo);
        return Result.success(sitepointPageInfo);
    }

    @RequestMapping("/SitePointTwo2/showTwo")
    @ResponseBody
    public Result select2(@RequestBody SitePointTwoVo sitePointTwoVo){
        sitePointTwoVo.setShifou(2);
        PageInfo<Sitepoint> sitepointPageInfo = siteService.selectAllSitepoint3(sitePointTwoVo);
        return Result.success(sitepointPageInfo);
    }


    @RequestMapping("/SitePointTwo/delete")
    @ResponseBody
    public Result delete(Integer id){
        try {
            Sitepoint sitepoint=new Sitepoint();

            sitepoint.setId(id);
            sitepoint.setSitetype(0);
            sitepoint.setShifou(2);

            siteService.updateSitepoint(sitepoint);
            return Result.success("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("删除失败");
        }
    }

    @RequestMapping("/SitePointTwo/updatetwo")
    @ResponseBody
    public Result update(Sitepoint sitepoint){
        try {
            siteService.updateSitepoint2(sitepoint);
            return Result.success("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("修改失败");
        }
    }

    @RequestMapping("/SitePointTwo/update")
    @ResponseBody
    public Result update(Long[] ids){
        try {
            Sitepoint sitepoint=new Sitepoint();
            sitepoint.setRouteid(routeid);

            for (Long id : ids) {
                Integer a = id.intValue();
                sitepoint.setId(a);
                sitepoint.setShifou(1);
                siteService.updateSitepoint(sitepoint);
            }
            return Result.success("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("修改失败");
        }
    }
}
